package jmine.tec.services.utils.replace.transformation;

import jmine.tec.services.utils.replace.api.ServiceBlock;
import jmine.tec.services.utils.replace.api.ServiceRow;
import jmine.tec.services.utils.replace.api.ServiceTransformation;

/**
 * @author lundberg
 */
public abstract class AbstractTransformation implements ServiceTransformation {

    protected final String action;

    protected final String name;

    public AbstractTransformation(String action, String name) {
        super();
        this.action = action;
        this.name = name;
    }

    public boolean shouldApply(ServiceBlock block) {
        if (block.getServices().size() != 0) {
            return this.matches(block.getServices().get(0));
        } else {
            return false;
        }
    }

    protected boolean matches(ServiceRow row) {
        return (this.action.equals(row.getAction().trim()) || ("#" + this.action).equals(row.getAction().trim()))
                && this.name.equals(row.getName());
    }
}
